<?php


class NetSign
{
    private $sign;
    private $uTime;

    public function __construct($s)
    {
        if (empty($_GET["s"])) {
            die("参数错误");
        }
        $spS = explode('$',$s);
        $this->sign = $spS[0];
        $this->uTime = $spS[1];
    }

    private function computeSign($t)
    {
        return md5(((30 + 15 * 30) + $t) . SqlConfig::$SQL_PASS);
    }

    private function verifySession()
    {
        if (!empty($_SESSION["sign"])) {
            if ($_SESSION["sign"] == $this->sign) {
                return false;
            }
        }
        return true;
    }

    public function verifySign()
    {
        if (!$this->verifySession()) {
            return false;
        }
        /*if (!empty($_SESSION["sign"])) {
            if ($_SESSION["sign"] == $this->sign) {
                return false;
            }
        }*/

        if ($this->computeSign($this->uTime) != $this->sign) {
            return false;
        }
        if (!($this->uTime > 3000 || $this->uTime < 3000)) {
            return false;
        }
        $_SESSION["sign"] = $this->sign;


        return true;
    }
}


/*$i = 0;
while (true) {
    if ($this->computeSign(time() + $i) == $this->sign) {
        return true;
        break;
    }
    if ($i > 5000) {
        break;
    }
    $i++;
}
return false;*/